import { UseOptions } from '../../interface/cmd'
import { openFile } from '../cmd'
import useBaseGenerator from './baseGenerator'
import useGenerateFile from './generateFile'
import { saveTypeScriptDefineFile } from './saveTsDefineFile'

export default async function useProtoMode(filePath: string, option: UseOptions) {
  // 生成js源文件，根据js源文件生成.d.ts文件
  await openFile(option.path)
  const pbtsFilePath = await useBaseGenerator(filePath, option)
  return Promise.all([
    saveTypeScriptDefineFile(pbtsFilePath),
    useGenerateFile(pbtsFilePath, option)
  ])
}
